package com.qf.controller;

import com.qf.entiy.Category;
import com.qf.entiy.Product;
import com.qf.service.CategoryService;

import com.qf.service.Impl.CategoryServiceImpl;
import com.qf.util.Constants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/*
    Dell
    2021/10/9
    11:58
*/
@WebServlet("/category")
public class CategoryController extends BaseController {
    public String showAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CategoryService categoryService = new CategoryServiceImpl();
        List<Category> categoryList = categoryService.showAll();
        request.setAttribute("categoryList",categoryList);
        return Constants.FORWARD+"/edit.jsp";
    }
    public String selectId(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        CategoryService categoryService = new CategoryServiceImpl();
        Product product = categoryService.showById(Integer.valueOf(id));
        List<Category> categoryList = categoryService.showAll();
        request.setAttribute("product",product);
        request.setAttribute("categoryList",categoryList);
        return Constants.FORWARD+"/edit.jsp";
    }
}
